<?php
/**
 * 快问项目/分页操作
 * Author: 小谢
 * Date: 2018-3-7
 */
namespace app\api\logic;

/**
 * 分页逻辑定义
 * Class CatsLogic
 * @package common\Logic
 */
class PageLogic
{
    public $page;
    public $thisPage;
    public $pagesize;
    public $count;

    /**
    *@brief 构造函数
    *@param $page type Int 当前分页数
    *@param $pagesize type 当前页多少条
    *@param $count type 总共页数
    *return mixd
    */
    public function __construct($page,$pagesize,$count) {
            $this->page = $page;//当前页
            $this->pagesize = $pagesize;//当前页多少条数
            $this->count = $count;//总共页数
            //$this->pagehandle();
    }
    
    /**
    *@brief 分页操作
    *return mixd
    */
    public function pageHandle() {

          if (!isset($this->pagesize)) {
              exit('Error:pagesize参数出错！');
          }

          $this->page = $this->page == 1 ? 0 : intval($this->page);

          $this->thisPage= $this->page == 0 ? 0 : intval($this->page -1);

          //开始页
          $pageStart = $this->page ? intval( $this->pagesize * $this->thisPage) : 0;

          //总共页数
          $totalPage = ceil($this->count / $this->pagesize);

          return array('pageStart'=>$pageStart,'pageSize'=>$this->pagesize,'totalPage'=>$totalPage);
    }
   
   
}